package com.djhu.newscollector.crawel.imp.worker;

import com.djhu.newscollector.core.Holder.JobHolder;
import com.djhu.newscollector.core.dispatch.JobDispatcher;
import com.djhu.newscollector.core.entity.Response;
import com.djhu.newscollector.core.job.BaseJob;
import com.djhu.newscollector.core.worker.Worker;
import com.djhu.newscollector.crawel.core.PageProcess;
import com.djhu.newscollector.crawel.core.ProcessMatcher;
import com.djhu.newscollector.crawel.core.Url;
import com.djhu.newscollector.crawel.imp.holder.BaseJobHolder;
import com.djhu.newscollector.crawel.net.DefaultHttpVisitor;
import com.djhu.newscollector.crawel.net.HttpRequest;
import com.djhu.newscollector.crawel.net.HttpVisitor;
import com.djhu.newscollector.crawel.net.Page;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * Created by zw on 2018/2/12.
 */
public class WangyiNewsWorker implements Worker{
    private static Logger logger = LogManager.getLogger(WangyiNewsWorker.class.getName());

    //private HttpVisitor httpVisitor = new DefaultHttpVisitor();

    private ProcessMatcher processMatcher;

//
//    private JobHolder jobHolder;
//
//    private JobDispatcher jobDispatcher;
//
//    private MongoService mongoService;
    @Override
    public Response process(BaseJob job) {

        NewsResponse newsResponse = new NewsResponse();
        if (job instanceof Url) {
            Url url = (Url)job;
            PageProcess pageProcess = processMatcher.match(url);
            return pageProcess.process(url);
        }else {
            throw new RuntimeException("type error");
        }
    }

    public ProcessMatcher getProcessMatcher() {
        return processMatcher;
    }

    public void setProcessMatcher(ProcessMatcher processMatcher) {
        this.processMatcher = processMatcher;
    }
}